### 解题思路#######
'''
1.判断正负数
2.正数字符串取反
3.负数去绝对值后字符串取反再乘以-1
'''

class Solution(object):
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
        # if x > (2 ** 31) - 1 or x < -2 ** 31:
        #     return 0
        if x > 0:
            x = int(str(x)[::-1])
            if x > (2 ** 31) - 1:
                return 0
        else:
            x = -1 * int(str(abs(x))[::-1])
            if x < -2 ** 31:
                return 0
        return int(x)

def main():
    x = int(input('x = '))
    x_rev = Solution().reverse(x)
    print(x_rev)

if __name__ == '__main__':
    main()
